package com.example.flowerpcback.controller;

import com.example.flowerpcback.dto.Roles;
import com.example.flowerpcback.req.RolesReq;
import com.example.flowerpcback.resp.CommonResp;
import com.example.flowerpcback.resp.PageResp;
import com.example.flowerpcback.resp.RolesResp;
import com.example.flowerpcback.services.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController //这是返回接口
@RequestMapping("/roles")
public class RoleController {

    private static final Logger LOG = LoggerFactory.getLogger(RoleController.class);

    @Resource
    private RoleService roleService;


    @PostMapping("/save")
    public CommonResp<Roles> save(@Valid @RequestBody RolesReq req){
        CommonResp resp= new CommonResp<>();
        Roles roles = roleService.save(req);
        resp.setData(roles);
        return  resp;
    }

    @GetMapping("/list")
    public CommonResp<PageResp<RolesResp>> list(@Valid RolesReq req){
        CommonResp<PageResp<RolesResp>> resp= new CommonResp<>();
        PageResp<RolesResp> pageResp = roleService.list(req);
        resp.setData(pageResp);
        return  resp;
    }

    @GetMapping("/all")
    public CommonResp<List<RolesResp>> all(@Valid RolesReq req){
        CommonResp<List<RolesResp>> resp= new CommonResp<>();
        List<RolesResp> lists = roleService.all(req);
        resp.setData(lists);
        return  resp;
    }

    @GetMapping("/delete")
    public CommonResp delete(@Valid RolesReq req){
        CommonResp resp= new CommonResp<>();
        roleService.delete(req);
        return  resp;
    }

}

